import { Injectable }       from "@angular/core";
import { HttpClient }       from "@angular/common/http";
import { ScopeAccessToken } from "../model/scope-access-token";
import { tap }              from "rxjs/operators";
import { Observable }       from "rxjs";

@Injectable({ providedIn: 'root' })
export class WxResourceService
{
    constructor( private http: HttpClient ) {}
    
    getOpenId( code: string ): Observable<ScopeAccessToken>
    {
        return this.http.get(`api/wx/openid?code=${ code }`).pipe(tap(( v: any ) =>
        {
            sessionStorage.setItem("openId", v.token.openId);
            sessionStorage.setItem("unionId", v.token.unionId)
        }))
    }
}
